package com.sykj.weichat.web;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import  com.sykj.weichat.service.BisBagRecordService;
import javax.servlet.http.HttpSession;
import com.sykj.weichat.service.BisBeautyRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.sykj.weichat.service.BisOpinionService;
import com.sykj.weichat.model.BisBeautyRecord;
import com.sykj.weichat.model.BisCustomUser;
import com.sykj.weichat.model.BisOpinion;
import com.sykj.util.ResultBody;
import com.sykj.weichat.service.BisCustomUserService;

/**
 * 
 * 类名:com.sykj.weichat.web.WeichatHomeController
 * 描述:微信个人中心
 * @author 张孝柱
 * 创建时间:2018年9月6日 
 * 修改说明:
 */
@Controller
@RequestMapping("/weichat/home")
public class WeichatHomeController {
	@Autowired
	BisCustomUserService BisCustomUserService;
    @Autowired
    BisBeautyRecordService BisBeautyRecordService;
    @Autowired
    BisOpinionService BisOpinionService;
	@RequestMapping("/")
	public String home(HttpSession session,Model model) {
		String mobile = (String) session.getAttribute("mobile");
		System.out.println(mobile+"==============");
		BisCustomUser getall = BisCustomUserService.getall(mobile);
		model.addAttribute("customUserPO", getall);
		return "weichat/my/home.jsp";
	}
	@RequestMapping("/goMyDetail")
	public String goMyDetail(HttpSession session,Model model) {
		String mobile = (String) session.getAttribute("mobile");
		BisCustomUser getall = BisCustomUserService.getall(mobile);
		model.addAttribute("customUserPO", getall);
		return "weichat/my/myDetail.jsp";
	}
	@RequestMapping("/updateMyInfo")
	@ResponseBody
	public String updateMyInfo(BisCustomUser bisCustomUser,Model model) {
		String result = "{\"appcode\":\"%s\", \"appmsg\":\"%s\" }";
		int update = BisCustomUserService.update(bisCustomUser);
		if (update>0) {
			result = String.format(result,"1", "Success!");

		} else {
			result = String.format(result,"0", "Failed!");
		}
		return result;
	}
	@RequestMapping("/goMyBeauty")
	public String goMyBeauty(HttpSession session,Model model) {
		String mobile = (String) session.getAttribute("mobile");
		BisCustomUser getall = BisCustomUserService.getall(mobile);
		model.addAttribute("customUserPO", getall);
		return "weichat/my/myBeauty.jsp";
	}
	/**
	 * 
	 * 简要说明：跳转交换颜值的页面
	 * 编写者：张孝柱
	 * 创建时间：2018年9月12日 
	 * @param 说明
	 * @return 说明
	 */
	@RequestMapping("/goExchangeBeauty")
	public String goExchangeBeauty(Model model,HttpSession session){
		String mobile = (String) session.getAttribute("mobile");
		model.addAttribute("mobile", mobile);
		return "weichat/my/exchangeBeauty.jsp";
	}
	/**
	 * 
	 * 简要说明：初始化颜值记录交易记录
	 * 编写者：张孝柱
	 * 创建时间：2018年9月12日 
	 * @param 说明
	 * @return 说明
	 */
	@RequestMapping("/initBeautyRecord")
	public String initBeautyRecord(){
		return "weichat/my/beautyRecordList.jsp";
	}
	/**
	 * 
	 * 简要说明：查询颜值记录
	 * 编写者：张孝柱
	 * 创建时间：2018年9月12日 
	 * @param 说明
	 * @return 说明
	 */
	@RequestMapping("/searchBeautyRecord")
	@ResponseBody
	public ResultBody searchBeautyRecord(){
		List<BisBeautyRecord> getall = BisBeautyRecordService.getall();
		return ResultBody.getData(getall.size(), getall, "success");
	}
	/**
	 * 
	 * 简要说明：初始化颜值记录交易记录
	 * 编写者：张孝柱
	 * 创建时间：2018年9月12日 
	 * @param 说明
	 * @return 说明
	 */
	@RequestMapping(value = "goFeedback")
	public String goFeedback(){
		return "weichat/my/feedback.jsp";
	}
	/**
	 * 
	 * 简要说明：保存反馈意见
	 * 编写者：张孝柱
	 * 创建时间：2018年9月12日 
	 * @param 说明
	 * @return 说明
	 */
	@RequestMapping(value = "saveOpinion")
	@ResponseBody
	public String saveOpinion(BisOpinion bisOpinion,HttpSession session){
		String result = "{\"appcode\":\"%s\", \"appmsg\":\"%s\" }";
		Date day=new Date();    
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
		String format = df.format(day);
		bisOpinion.setCreate_time(format);
		SimpleDateFormat df1 = new SimpleDateFormat("yyyyMMddHHmmss"); 
		bisOpinion.setOpinion_id( df1.format(day));
		
		String custom_user_id = (String) session.getAttribute("custom_user_id");
		bisOpinion.setCustom_user_id(custom_user_id);
		int insert = BisOpinionService.insert(bisOpinion);
		if (insert>0) {
			result = String.format(result,"1", "Success!");

		} else {
			result = String.format(result,"0", "Failed!");
		}
		return result;
	}
}
